package com.example.demo.service;

import com.example.demo.entity.Course;
import com.example.demo.mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程信息业务逻辑层
 */
@Service
public class CourseService {

    @Autowired
    private CourseMapper courseMapper;

    public int addCourse(Course course) {
        return courseMapper.insertCourse(course);
    }

    public Course getCourseById(String courseId) {
        return courseMapper.selectCourseById(courseId);
    }
    // 按学期ID筛选课程

    public List<Course> findCoursesBySemesterId(String semesterId) {
        return courseMapper.selectCoursesBySemesterId(semesterId);
    }

    public List<Course> getAllCourses() {
        return courseMapper.selectAllCourses();
    }

    public int updateCourseInfo(Course course) {
        return courseMapper.updateCourse(course);
    }

    public int deleteCourse(String courseId) {
        return courseMapper.deleteCourseById(courseId);
    }

    /**
     * 根据教师ID获取所有课程
     * @param teacherId 教师ID
     * @return 课程列表
     */
    public List<Course> getCoursesByTeacherId(Integer teacherId) {
        return courseMapper.selectCoursesByTeacherId(teacherId);
    }
}